import {
  Controller,
  Post,
  Request,
  UseGuards,
  HttpCode,
  HttpStatus,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { AuthService } from './auth.service';
import { ApiOperation, ApiResponse, ApiBody, ApiTags } from '@nestjs/swagger';
import { LoginDto } from '../user/dto/login.dto';
import { LoginResDto } from '../user/dto/loginRes.dto';

@ApiTags('auth')
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}
  @UseGuards(AuthGuard('local'))
  @Post('/login')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: '用户登录', description: '用户登录' })
  @ApiBody({ type: LoginDto, description: '需要输入用户名和密码' })
  @ApiResponse({
    status: 200,
    type: LoginResDto,
  })
  async login(@Request() request): Promise<any> {
    return this.authService.login(request.user);
  }
}
